#ifndef ANALYZE_H
#define ANALYZE_H
#include "nodes/nodes.h"
#include "nodes/op_list.h"
#include "nodes/prim_nodes.h"
#include "nodes/parse_nodes.h"

query_t *parse_analyze(list_t *pl);
parse_state_t *make_parse_state_t();
query_t *transform_stmt(parse_state_t *pstate, node_t *parse_tree);
query_t *transform_delete_stmt(parse_state_t *pstate, delete_stmt_t *stmt);
query_t *transform_insert_stmt(parse_state_t *pstate, insert_stmt_t *stmt);
query_t *transform_select_stmt(parse_state_t *pstate, select_stmt_t *stmt);
query_t *transform_update_stmt(parse_state_t *pstate, update_stmt_t *stmt);
node_t *transform_where_clause(parse_state_t *pstate, node_t *a_expr);

void make_range_table(parse_state_t *pstate, const char *relname, list_t *frm_list);
int range_table_posn(list_t *rtable, const char *rangevar);
list_t *make_target_list(parse_state_t *pstate, list_t *cols, list_t *exprs);
list_t *transform_target_list(parse_state_t *pstate,
                                 list_t *targetlist,
                                 bool isInsert,
                                 bool isUpdate);
list_t *transform_sort_clause(list_t *order_list, list_t *target_list, char *unique_flag);
list_t *transform_group_clause(parse_state_t *pstate, list_t *grouplist);
const char *parse_column_name(parse_state_t *pstate, char *name, bool *is_rel_name);
expr_t *make_op(char *opname, node_t *ltree, node_t *rtree);
oid_t expr_type(node_t *expr);
range_tbl_entry_t *make_range_table_entry(const char *rel_name, bool inh, const char *ref_name);
unsigned int get_attnum(int rel_dim, char *att_name);
list_t *transform_group_stmt(parse_state_t *pstate, list_t *grouplist);
#endif // ANALYZE_H
